// pages/dailiangfang/upkeep.js
Page({
  data: {
    scrollviewheight: '',
    ci_rwdid: '',
    showView: true,
    showView2: true,
    showView3: true,
    showView4: true,
    showView5: true,
    showView6: true,
    ca_ReqConTime: '',            //施工时间
    ca_ProductProtection: '',     //公共区域保护
    ca_PropertyInsurance: '',     //工程一切险要求
    ca_DesignatedFireCompany: '', //指定消防公司 int
    ca_DesignatedAirCompany: '',  //指定空调公司 int
    ca_DesignatedSinotrans: '',   //指定垃圾外运 int

  },
  onLoad: function (options) {

    var that = this
    that.setData({
      ci_rwdid: options.ci_rwdid,
    })
    // 获取系统高度
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          scrollviewheight: res.screenHeight - 118
        })
      },
    })
 
    //接口一获取数据
    wx.request({
      url: 'https://api.wenes.cn/JD/GetPropertyInfo?ci_rwdid=' + that.data.ci_rwdid,
      success: function (res) {
        console.log('物业：', res.data)
        var item = res.data.Table[0]
        that.setData({
          ca_ReqConTime: item.ca_ReqConTime,
          ca_ProductProtection: item.ca_ProductProtection,
          ca_PropertyInsurance: item.ca_PropertyInsurance,
          ca_DesignatedFireCompany: item.ca_DesignatedFireCompany,
          ca_DesignatedAirCompany: item.ca_DesignatedAirCompany,
          ca_DesignatedSinotrans: item.ca_DesignatedSinotrans,
        })
      }
    })
  },

  //点击标题隐藏和显示
  title_time: function () {
    var that = this
    that.setData({
      showView: (!that.data.showView)
    })
  },
  // 点击选项卡--施工时间
  selector_time1: function (e) {
    var that = this
    that.setData({
      showView: (!that.data.showView),
      ca_ReqConTime: '白天'
    })
    wx.setStorage({
      key: 'ca_ReqConTime',
      data: that.data.ca_ReqConTime,
    })
  },
  selector_time2: function (e) {
    var that = this
    that.setData({
      showView: (!that.data.showView),
      ca_ReqConTime: '晚上'
    })
    wx.setStorage({
      key: 'ca_ReqConTime',
      data: that.data.ca_ReqConTime,
    })
  },
  selector_time3: function (e) {
    var that = this
    that.setData({
      showView: (!that.data.showView),
      ca_ReqConTime: '均可'
    })
    wx.setStorage({
      key: 'ca_ReqConTime',
      data: that.data.ca_ReqConTime,
    })
  },
  //点击标题隐藏和显示
  title_protection: function () {
    var that = this
    that.setData({
      showView2: (!that.data.showView2)
    })
  },
  // 点击选项卡--公共区域保护
  selector_protection1: function (e) {
    var that = this
    that.setData({
      showView2: (!that.data.showView2),
      ca_ProductProtection: '是'
    })
    wx.setStorage({
      key: 'ca_ProductProtection',
      data: that.data.ca_ProductProtection,
    })
  },
  selector_protection2: function (e) {
    var that = this
    that.setData({
      showView2: (!that.data.showView2),
      ca_ProductProtection: '否'
    })
    wx.setStorage({
      key: 'ca_ProductProtection',
      data: that.data.ca_ProductProtection,
    })
  },
  //点击标题隐藏和显示
  title_insurance: function () {
    var that = this
    that.setData({
      showView3: (!that.data.showView3)
    })
  },
  // 点击选项卡--工程一切险要求
  selector_insurance1: function (e) {
    var that = this
    that.setData({
      showView3: (!that.data.showView3),
      ca_PropertyInsurance: '是'
    })
    wx.setStorage({
      key: 'ca_PropertyInsurance',
      data: that.data.ca_PropertyInsurance,
    })
  },
  selector_insurance2: function (e) {
    var that = this
    that.setData({
      showView3: (!that.data.showView3),
      ca_PropertyInsurance: '否'
    })
    wx.setStorage({
      key: 'ca_PropertyInsurance',
      data: that.data.ca_PropertyInsurance,
    })
  },
  //点击标题隐藏和显示
  title_firecompany: function () {
    var that = this
    that.setData({
      showView4: (!that.data.showView4)
    })
  },
  // 点击选项卡--指定消防公司
  selector_firecompany1: function (e) {
    var that = this
    that.setData({
      showView4: (!that.data.showView4),
      ca_DesignatedFireCompany: 1
    })
    wx.setStorage({
      key: 'ca_DesignatedFireCompany',
      data: that.data.ca_DesignatedFireCompany,
    })
  },
  selector_firecompany2: function (e) {
    var that = this
    that.setData({
      showView4: (!that.data.showView4),
      ca_DesignatedFireCompany: 2
    })
    wx.setStorage({
      key: 'ca_DesignatedFireCompany',
      data: that.data.ca_DesignatedFireCompany,
    })
  },
  //点击标题隐藏和显示
  title_aircompany: function () {
    var that = this
    that.setData({
      showView5: (!that.data.showView5)
    })
  },
  // 点击选项卡--指定空调公司
  selector_aircompany1: function (e) {
    var that = this
    that.setData({
      showView5: (!that.data.showView5),
      ca_DesignatedAirCompany: 1
    })
    wx.setStorage({
      key: 'ca_DesignatedAirCompany',
      data: that.data.ca_DesignatedAirCompany,
    })
  },
  selector_aircompany2: function (e) {
    var that = this
    that.setData({
      showView5: (!that.data.showView5),
      ca_DesignatedAirCompany: 2
    })
    wx.setStorage({
      key: 'ca_DesignatedAirCompany',
      data: that.data.ca_DesignatedAirCompany,
    })
  },
  //点击标题隐藏和显示
  title_sinotrans: function () {
    var that = this
    that.setData({
      showView6: (!that.data.showView6)
    })
  },
  // 点击选项卡--指定垃圾外运
  selector_sinotrans1: function (e) {
    var that = this
    that.setData({
      showView6: (!that.data.showView6),
      ca_DesignatedSinotrans: 1
    })
    wx.setStorage({
      key: 'ca_DesignatedSinotrans',
      data: that.data.ca_DesignatedSinotrans,
    })
  },
  selector_sinotrans2: function (e) {
    var that = this
    that.setData({
      showView6: (!that.data.showView6),
      ca_DesignatedSinotrans: 2
    })
    wx.setStorage({
      key: 'ca_DesignatedSinotrans',
      data: that.data.ca_DesignatedSinotrans,
    })
  },

  // 提交数据
  submit: function () {
    var that = this
    if (that.data.ci_rwdid == null               ||
      that.data.ca_ReqConTime == null            ||  
      that.data.ca_ProductProtection == null     ||  
      that.data.ca_PropertyInsurance == null     ||  
      that.data.ca_DesignatedFireCompany == null ||  
      that.data.ca_DesignatedAirCompany == null  ||  
      that.data.ca_DesignatedSinotrans == null  
    ) {
      // wx.showToast({
      //   title: '请将信息填写完整!',
      //   icon: 'warn',
      //   duration: 2000
      // })
      wx.showModal({
        title: '提示',
        content: '请将信息填写完整!',
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定')
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    } else {
      wx.request({
        url: 'https://api.wenes.cn/JD/UpdatePropertyInfo',
        method: 'POST',
        header: {
          'content-type': 'application/json'
        },
        data: {
          ci_rwdid: that.data.ci_rwdid,
          ca_ReqConTime: that.data.ca_ReqConTime,            //施工时间
          ca_ProductProtection: that.data.ca_ProductProtection,//公共区域保护
          ca_PropertyInsurance: that.data.ca_PropertyInsurance,//工程一切险要求
          ca_DesignatedFireCompany: that.data.ca_DesignatedFireCompany,//消防公司
          ca_DesignatedAirCompany: that.data.ca_DesignatedAirCompany,//空调公司
          ca_DesignatedSinotrans: that.data.ca_DesignatedSinotrans,//垃圾外运
        },
        success: function (res) {
          console.log(res)
          if (res.data == 1) {
            wx.showToast({
              title: '成功',
              icon: 'success',
              duration: 2000
            })
            wx.clearStorage()
          } else {
            wx.showToast({
              title: '失败',
              icon: 'success',
              duration: 2000
            })
          }
        }
      })
    }

  },

  // 页面跳转
  measureroom: function () {
    var that = this
    wx.redirectTo({
      url: 'measureroom?ci_rwdid=' + that.data.ci_rwdid,
    })
  },
  surroundings: function () {
    var that = this
    wx.redirectTo({
      url: 'surroundings?ci_rwdid=' + that.data.ci_rwdid + '&WorksID=' + that.data.WorksID + '&CustomerID=' + that.data.CustomerID,
    })
  },
  demand: function () {
    var that = this
    wx.redirectTo({
      url: 'demand?ci_rwdid=' + that.data.ci_rwdid,
    })
  },



})